import { injectReducer } from '../../store/reducers'
import TMDFormHome from './components/TMDFormHome'
export default (store) => ({
  path : 'tmdform',
  indexRoute:{
    component:TMDFormHome
  },
  childRoutes: [{
    path: 'manager/:formId',
    getComponent(nextState, cb) {
      require.ensure([], (require) => {
        const QuestionsManager = require('./routes/containers/FieldsContainer').default
        const reducer = require('./routes/modules/fields').default
        injectReducer(store, { key: 'fields', reducer })
        cb(null, QuestionsManager)
      }, 'fields')
    }
  }],
  /*  Async getComponent is only invoked when route matches   */
  getComponent (nextState, cb) {
    /*  Webpack - use 'require.ensure' to create a split point
        and embed an async module loader (jsonp) when bundling   */
    require.ensure([], (require) => {
      /*  Webpack - use require callback to define
          dependencies for bundling   */
      const TMDForm = require('./containers/TMDFormContainer').default
      const reducer = require('./modules/tmdform').default

      /*  Add the reducer to the store on key 'counter'  */
      injectReducer(store, { key: 'tmdform', reducer })

      /*  Return getComponent   */
      cb(null, TMDForm)

    /* Webpack named bundle   */
    }, 'tmdform')
  }
})

